﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CanDoo;
using CanDoo.Core;
using CanDoo.Core.Data;
using CanDoo.Data;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Oil.Core.DTOs;
using CanDoo.Oil.Core.Models;
using System.Data.Entity;
using System.Threading.Tasks;

namespace CanDoo.Oil.Core.Services
{
    /// <summary>
    /// 业务实现——店铺活动
    /// </summary>
    public class StoreActivityService : CanDoo.Data.Entity.Services.ServiceBase<StoreActivity>, IStoreActivityContract
    {
        public StoreActivityService()
        {

        }

        /// <summary>
        /// 1.1.5 本店活动:输入门店相关信息去后台请求活动详情
        /// </summary>
        /// <param name="storeNoInfo">店铺号</param>
        /// <returns>店铺活动信息数组,如果找不到返回null</returns>
        public async Task<StoreCampaign[]> GetByStoreNoAsync(string storeNo)
        {
            using (DbScopeFactory.CreateReadOnly())
            {
                //var list = Entities.Where(p => p.).Select(p => new StoreCampaign { }).ToArray();
                //return list;
                return await Entities.Where(p => p.Customer.CardNo == storeNo || p.CustomerId == null)
                    .Select(p => new StoreCampaign
                    {
                        beginTime = p.StartTime,
                        endTime = p.EndTime,
                        createTime = p.CreatedTime,
                        @event = p.Introduction,
                        eventUrl = p.Url,
                        id = p.Id,
                        type = "pad"
                    }).ToArrayAsync();
            }
        }
    }
}
